package com.zzptc.easyshop.servlet;

import com.zzptc.easyshop.dao.GoodTypeDaoImp;
import com.zzptc.easyshop.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "UserMangerServlet")
public class UserMangerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //处理编码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //从数据库红得到所有用户
        GoodTypeDaoImp.IDAO dao=new UserDao();
        //准备放所有的用户信息
        List list=new ArrayList();
        try {
            list=dao.getAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //传递数据到user.jsp
        HttpSession session=request.getSession();
        session.setAttribute("allusers",list);
        //跳转
        request.getRequestDispatcher("manager/user.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
